import React, {Component} from 'react';
import Middle from './middle'

/*
  如果要子组件给父组件传数据
  1.在子组件上先定义一个onReceiveMiddleValue配置属性props
  2.onReceiveMiddleValue关联receiveMiddleValue函数
  3.子组件传到父组件的值以参数的形式传入receiveMiddleValue(子组件的值)
 */
class TopComponent extends Component {
  constructor() {
    super();
    this.state = {};
  }

  showSomething() {
    console.log(this.props)
  }

  receiveMiddleValue(value) {
    console.log(value);
  }
  render() {
    let topArray = ['t1', 't2']
    let middleArray = []
    return (
      <div>
        我是最外层组件
        <Middle
          topToMiddle='从top传到middle'
          topArray={topArray}
          middleArray={middleArray}
          onReceiveMiddleValue={this.receiveMiddleValue}></Middle>
        <button onClick={this
          .showSomething
          .bind(this)}>top中按钮</button>
      </div>
    )
  }
}

export default TopComponent